package com.ruoyi.mall.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.domain.Specifications;
import com.ruoyi.mall.service.ISpecificationsService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 规格参数Controller
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/mall/specifications")
public class SpecificationsController extends BaseController
{
    @Autowired
    private ISpecificationsService specificationsService;

    /**
     * 查询规格参数列表
     */
    @PreAuthorize("@ss.hasPermi('mall:specifications:list')")
    @GetMapping("/list")
    public TableDataInfo list(Specifications specifications)
    {
        startPage();
        List<Specifications> list = specificationsService.selectSpecificationsList(specifications);
        return getDataTable(list);
    }

    /**
     * 导出规格参数列表
     */
    @PreAuthorize("@ss.hasPermi('mall:specifications:export')")
    @Log(title = "规格参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Specifications specifications)
    {
        List<Specifications> list = specificationsService.selectSpecificationsList(specifications);
        ExcelUtil<Specifications> util = new ExcelUtil<Specifications>(Specifications.class);
        util.exportExcel(response, list, "规格参数数据");
    }

    /**
     * 获取规格参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:specifications:query')")
    @GetMapping(value = "/{specId}")
    public AjaxResult getInfo(@PathVariable("specId") Long specId)
    {
        return success(specificationsService.selectSpecificationsBySpecId(specId));
    }

    /**
     * 新增规格参数
     */
    @PreAuthorize("@ss.hasPermi('mall:specifications:add')")
    @Log(title = "规格参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Specifications specifications)
    {
        return toAjax(specificationsService.insertSpecifications(specifications));
    }

    /**
     * 修改规格参数
     */
    @PreAuthorize("@ss.hasPermi('mall:specifications:edit')")
    @Log(title = "规格参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Specifications specifications)
    {
        return toAjax(specificationsService.updateSpecifications(specifications));
    }

    /**
     * 删除规格参数
     */
    @PreAuthorize("@ss.hasPermi('mall:specifications:remove')")
    @Log(title = "规格参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{specIds}")
    public AjaxResult remove(@PathVariable Long[] specIds)
    {
        return toAjax(specificationsService.deleteSpecificationsBySpecIds(specIds));
    }
}
